package com.itgaoshu.hospitalproject.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.hospitalproject.bean.Lcheckup;
import com.itgaoshu.hospitalproject.bean.Register;
import com.itgaoshu.hospitalproject.service.LoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("liao")
public class LoutController {
    //出院结算管理
    @Autowired
    private LoutService loutService;

    //跳转到出院页面
    @RequestMapping("leave")
    public String leave(){
        return "liao/leave";
    }

    //查询已出院患者的记录
    @RequestMapping("selRegisters")
    @ResponseBody
    public Object selRegisters(Integer page, Integer limit, String userNames){
        Register register = new Register();
        register.setUserName(userNames);
        PageHelper.startPage(page,limit);
        List<Register> registers = loutService.selRegisters(register);
        PageInfo pageInfo = new PageInfo(registers);
        Map<String,Object> tableDate = new HashMap<>();
        tableDate.put("code",0);
        tableDate.put("msg","");
        tableDate.put("count",pageInfo.getTotal());
        tableDate.put("data",pageInfo.getList());
        return tableDate;
    }

    //查询该患者是否还有药品要取出才能出院
    @ResponseBody
    @RequestMapping("selYaos")
    public Object selYaos(Register register){
        int i = loutService.selYaos(register);
        return i;
    }

    //患者出院
    @RequestMapping("updLeave")
    @ResponseBody
    public Object upLeave(Register register){
        int i = loutService.updateR(register);
        if(i==1){
            return "出院成功";
        }else{
            return "出院失败";
        }

    }

    //费用详情的信息中出院的个人详情
    @ResponseBody
    @RequestMapping("selregis")
    public Object selregis(Integer registerid){
        Register register = new Register();
        register.setRegisterid(registerid);
        List<Register> registers = loutService.selRegisters(register);
        return registers;
    }

    //费用详情信息中的查询该患者出院之后的再一次的复查情况
    @RequestMapping("selCheckup")
    @ResponseBody
    public Object selCheckup(Integer page,Integer limit,Integer registerid){
        Register register = new Register();
        register.setRegisterid(registerid);
        PageHelper.startPage(page,limit);
        List<Lcheckup> lcheckups = loutService.selCheckup(register);
        PageInfo pageInfo = new PageInfo(lcheckups);
        HashMap<String, Object> tableDate = new HashMap<>();
        tableDate.put("code",0);
        tableDate.put("msg","");
        tableDate.put("count",pageInfo.getTotal());
        tableDate.put("data",pageInfo.getList());
        return tableDate;
    }



}
